Ext.define('GBIF.MainToolbar', {
		extend: 'Ext.toolbar.Toolbar'	
	,	alias: 'widget.mainToolbar'
	,	border: false
	,	initComponent: function() {
			this.closeProject = Ext.create('Ext.Button', {
					text:  this.txtCloseProject
				,	iconCls: 'icon_application_go'
			});
			this.projectName =  Ext.create('Ext.form.Label', {
					text: this.txtProject
			});
			this.viewBtn = Ext.create('Ext.button.Button',{
					text: this.txtView
				,	iconCls: 'icon_layout'	
				,	menu: {
						items: [{
								text: this.txtOverview
							,	scope: this
							,	txt: 'Overview'
							,	checked: true
							,	group: 'view'
							,	handler: function(){
									this.fireEvent('changeCard', 0, this);
								}
						}, {
								text: this.txtData
							,	scope: this
							,	checked: false
							,	txt: 'Data'
							,	group: 'view'
							,	handler: function(){
									this.fireEvent('changeCard', 1, this);
								}
						}, {
								text: this.txtSummary
							,	scope: this
							,	checked: false
							,	txt: 'Summary'
							,	group: 'view'
							,	handler: function(){
									this.fireEvent('changeCard', 2, this);
								}
						}]
					}
			});
			this.items = [
					'&nbsp;'
				,	this.projectName
				, this.viewBtn
				, {
						text: this.txtHelp
					,	iconCls: 'icon_help'	
					,	menu: {
							items: [{
									text: this.txtAbout
								,	iconCls: 'icon_information'
								,	scope: this
								,	handler: function() {									
										Ext.Msg.alert(this.msgAboutTitle, this.msgAboutText);
									}
							}, {
									text: this.txtGettingStarted
								,	iconCls: 'icon_page'	
								,	handler: function() { 
										window.open(Config.getStartedUrl, '_blank');
									}
							}, {
									text: this.txtProjectWebsite
								,	iconCls: 'icon_page'		
								,	handler: function() { 
										window.open(Config.projectUrl, '_blank');
									}
							}, {
									text: this.txtReportIssue
								,	iconCls: 'icon_page'
								,	scope: this	
								,	handler: function() { 
										window.open(Config.issuesUrl, '_blank');
									}
							}]
						}
					}
				, '->',  this.closeProject
			];
			
			this.callParent();
		}
	,	setProjectName: function(pid){
			this.projectName.setText(this.txtProject + pid);
			this.doLayout();
		}
	,	statusEnableDisable: function(){
			var status = GBIF.currentStatus;
			switch(status){
				case 'NEW':
				case "CLASSIFYING":
				case "ARCHIVING":
				case 'ERROR':
					this.disableChild();
					break;

				default:
					this.enableChild();
			}
		}		
	,	enableChild: function(){
			this.viewBtn.menu.items.each(function(item){
				if (item.disabled) {
					item.enable();
				}
			}, this);
		}
	,	disableChild: function(){
			this.viewBtn.menu.items.each(function(item){
				if (!item.disabled && item.txt != "Overview") {
					item.disable();
				}
			}, this);
		}
});